﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Libs.Db;

namespace Libs.HR
{
    public class ContractType
    {
        public int TypeID { get; set; }
        public string Name { get; set; }
        public string ShortName { get; set; }
        public int Order { get; set; }
        public int ReturnValue { get; set; }

        public ContractType()
        {

        }

        ~ContractType()
        {

        }

        public virtual void Dispose()
        {

        }

        /// <summary>
        /// Lấy giá trị ContractType theo ID
        /// </summary>
        /// <param name="typeID"></param>
        /// <returns></returns>
        public ContractType Get(int typeID)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetInstanceSP<ContractType>("sp_ContractType_Select",
                new SqlParameter("@TypeID", typeID));
        }

        /// <summary>
        /// Lấy giá trị ContractType theo ID
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public ContractType Get()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetInstanceSP<ContractType>("sp_ContractType_Select",
                new SqlParameter("@TypeID", TypeID));
        }

        /// <summary>
        /// Thêm mới ContractType
        /// </summary>
        public void Add()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            SqlParameter[] pars = new SqlParameter[4];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@Name", Name);
            pars[2] = new SqlParameter("@ShortName", ShortName);
            pars[3] = new SqlParameter("@Order", Order);

            db.ExecuteNonQuerySP("sp_ContractType_Insert", pars);
            TypeID = Convert.ToInt32(pars[0].Value);
        }

        /// <summary>
        /// Cập nhật Contract
        /// </summary>
        public void Update()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            SqlParameter[] pars = new SqlParameter[5];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@TypeID", TypeID);
            pars[2] = new SqlParameter("@Name", Name);
            pars[3] = new SqlParameter("@ShortName", ShortName);
            pars[4] = new SqlParameter("@Order", Order);

            db.ExecuteNonQuerySP("sp_ContractType_Update", pars);
            ReturnValue = Convert.ToInt32(pars[0].Value);
        }

        /// <summary>
        /// Xoá Contract
        /// </summary>
        /// <param name="typeID"></param>
        public void Delete(int typeID)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);

            db.ExecuteNonQuerySP("sp_ContractType_Delete",
                new SqlParameter("@TypeID", typeID));
        }

        /// <summary>
        /// Xoá Contract
        /// </summary>
        public void Delete()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);

            db.ExecuteNonQuerySP("sp_ContractType_Delete",
                new SqlParameter("@TypeID", TypeID));
        }

        public DataTable GetTList()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetDataTableSP("sp_ContractType_SelectList");
        }

        public List<ContractType> GetList()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetListSP<ContractType>("sp_ContractType_SelectList");
        }
    }
}
